package spring.configuration;

import com.me.common.pojo.Parent;
import com.me.common.pojo.Son;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import static spring.configuration.AppConfig.*;

/**
 * 1，测试 @Configuration 注解的 full模式、lite模式    <p>
 * 2，测试哪些配置方式会被 ConfigurationClassPostProcessor 识别 java配置类：源码见 -- ConfigurationClassBeanDefinitionReader#loadBeanDefinitions()
 * <blockquote>
 *     1) 带 @PropertySources 注解的类    <p>
 *     2) 带 @ComponentScan 注解的类    <p>
 *     3) 被 @Import导入的类 <p>
 *     4) 带 @Import 注解的类   <p>
 *     5) 带 @ImportResource 注解的类   <p>
 *     6) 类上无注解但是内部有 @Bean的类 <p>
 *     7) 带 @Component 或 @Configuration 注解的类    <p>
 * </blockquote>
 *
 * @author ME
 * @date   2020/5/22
 */
public class TestConfiguration {

    public static void main(String[] args) {
        // System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "H:\\kotlinSpace\\testME\\testJDK8\\src\\main\\java\\spring\\configuration\\cglibClass");
        ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

        AppConfig appConfig = context.getBean(AppConfig.class);
        System.out.println(appConfig);

        // bean情况
        Son son = context.getBean(Son.class);
        Parent parent = context.getBean(Parent.class);

        System.out.println("容器内的Son实例：" + son.hashCode());
        System.out.println("容器内Person持有的Son实例：" + parent.getSon().hashCode());
        System.out.println(parent.getSon() == son);

        System.out.println(context.getBean(ComponentConfig.class));
        System.out.println(context.getBean(ImportResourceConfig.class));
        System.out.println(context.getBean(BeImportedConfig.class));
        System.out.println(context.getBean(ImportConfig.class));
        System.out.println(context.getBean(ComponentScanConfig.class));
        System.out.println(context.getBean(NoAnnotationConfig.class));
    }

}
